package cn.rongdao.jrkabao.ui.loan.uicomponent;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import java.util.List;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.loan.ApplySuccessBean;
import cn.rongdao.jrkabao.constant.InfoConstant;
import cn.rongdao.jrkabao.ui.loan.LoanCommitActivity;
import cn.rongdao.jrkabao.ui.loan.adapter.ApplySuccessAdapter;
import cn.rongdao.jrkabao.ui.loan.adapter.viewholder.ApplySuccessViewHolder;
import cn.rongdao.jrkabao.ui.webview.WebViewActivity;


/**
 * Created by jack on 2017/8/24
 */

public class ApplySuccessListUIComponent extends LinearLayout {

    private CommonHeaderUIComponent mCommonHeaderUIComponent;

    public ApplySuccessListUIComponent(Context context) {
        super(context);
    }

    public ApplySuccessListUIComponent(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ApplySuccessListUIComponent(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private RecyclerView recyclerView;

    private ApplySuccessAdapter mAdapter;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        mCommonHeaderUIComponent = (CommonHeaderUIComponent) findViewById(R.id.lasl_header);
        recyclerView = (RecyclerView) findViewById(R.id.lasl_recyclerview);
        mAdapter = new ApplySuccessAdapter(getContext());

        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(mAdapter);

        mAdapter.setApplySuccessClickListener(new ApplySuccessViewHolder.OnApplySuccessClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                ApplySuccessBean.ReaultListBean.ProductListBean productListBean = mAdapter.getDataList().get(position);
                if (productListBean.getCate_id() == 1) {
                    WebViewActivity.start(getContext(), productListBean.getLink());
                } else {
                    LoanCommitActivity.startWithOtherJump(getContext(), String.valueOf(productListBean.getCate_id()), String.valueOf(productListBean.getProduct_id()), InfoConstant.PAGE_SOURCE_DEFAULT, productListBean.getOrg_name());
                }
            }
        });
    }

    public void setAdapterDataList(List<ApplySuccessBean.ReaultListBean.ProductListBean> dataList) {
        setVisibility(View.VISIBLE);
        mAdapter.setDataList(dataList);
    }

    public void setContent(String content) {
        mCommonHeaderUIComponent.setContent(content);
    }
}